#!/usr/bin/env narwhal
var gelatin = require('gelatin');  // under test

var file = require('file'),
    os = require('os'),
    json = require('json'),
    assert = require('test/assert');

var narcissus = require('narcissus'),
    oil = require('oil'),
    log = require('oil/log');
    packages = require('gelatin/packages');

// TODO:
//
// Construct a mock FileSystem with contentsOF
// Possibly put this in filetree

exports.testResolveRelativeRequires = function() {
  var deps = [
      {varName: 'foo', modName: './foo'},
      {varName: 'bar', modName: '../bar'},
  ];

  gelatin.resolveRelativeRequires(deps, 'spam/eggs');

  print(json.stringify(deps));
  assert.eq('spam/foo', deps[0].modName);
  assert.eq('bar', deps[1].modName);
}

exports.testDependency = function() {
  var d = new gelatin.Dependency(
      'foo', 'foo', [{fullPath: 'foo.js', handle: null}]);
  log.info('D: %s', d);
}

exports.testCrawl = function() {
  var fs = oil.FileSystem('/home/andy/git/narwhal2/packages/oil'),
      p = new packages.MaybePackage(fs);
  var set = packages.PackageSet([p]);

  try{
  gelatin.crawlDeps('oil', set, {}, 'node');
  }catch(e){
    print(e);
    print(e.stack);
  }
}

if (require.main === module.id) {
  require("test/runner").run(exports);
}
